﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Inspired.Euler
{
    public static class Problem041
    {
        public static long Solve()
        {
            long[] digits = new long[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            return Enumerable.Range(1, digits.Length)
                    .SelectMany(length => 
                        digits.Take(length).Permute()
                        .Select(seq => seq.ToInt64()))
                    .Where(number => number.IsPrime())
                    .Max();
        }
    }
}